package com.topnav.mc.admin.entity.wrapper;

import com.topnav.mc.admin.entity.param.OperateLogParam;
import com.topnav.mc.base.mc.McWrapper;

/**
 * @Author: kenny
 * @Date: 2024/3/29 17:09
 */
public class OperateLogWrapper extends McWrapper<OperateLogParam> {

    public OperateLogWrapper(OperateLogParam entity) {
        super(entity);
        if (this.permissionGrade != null ){
            if (this.permissionGrade.getPermissionLevel() == 1){
                this.eq("l.user_id",this.permissionGrade.getUserId());
            }else if (this.permissionGrade.getPermissionLevel() == 2){
                this.eq("u.org_id",this.permissionGrade.getOrgId());
            }else if (this.permissionGrade.getPermissionLevel() == 3 || this.permissionGrade.getPermissionLevel() == 4){
                this.likeRight("o.path",this.permissionGrade.getOrgPath());
            }
        }

        if (entity != null){
            if (entity.getId()!=null){this.eq("l.id",entity.getId());}
            if (entity.getUserId()!=null){this.eq("l.user_id",entity.getId());}
            if (entity.getLogType()!=null){this.eq("l.log_type",entity.getLogType());}
            if (entity.getFunctionId()!=null){this.eq("l.function_i",entity.getFunctionId());}
            if (entity.getFrom()!=null){
                this.ge("l.time",entity.getFrom());
            }
            if (entity.getTo()!=null){
                this.le("l.time",entity.getTo());
            }

        }
        this.orderByDesc("l.id");
    }
}
